home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 9 / The PC-SIG Library on CD ROM - Ninth Edition.iso / 401_500 / DISK0443 / DISK0443.ZIP / TSCORE.S3L < prev    next >
Text File  |  1987-01-09  |  11KB  |  259 lines

  1.  SFTRAN3/PDS Level 16-f  01/09/87  14:37  TSCORE.S3I
  2.     100       program TSCORE
  3.     200 c 
  4.     300 c     Compute weighted average of assignment and test scores, and the
  5.     400 c     T score where T = 10*((x-mu)/sigma) + 50, mu = mean, sigma =
  6.     500 c     standard deviation.
  7.     600 c 
  8.     700 c     *****     Input     **********************************************
  9.     800 c 
  10.     900 c     First is a line that is used as a page heading for all output.
  11.    1000 c     This should not be enclosed in quotes.
  12.    1100 c 
  13.    1200 c     Second is number of scores (integer) followed by pairs consisting
  14.    1300 c     of possible score (integer) and weight (integer), all separated by
  15.    1400 c     commas.
  16.    1500 c 
  17.    1600 c     Remaining inputs each consist of student name in quotes
  18.    1700 c     (character) followed by student ID number (integer) and all scores
  19.    1800 c     (integer), with all quantities for each student separated by
  20.    1900 c     commas.
  21.    2000 c 
  22.    2100 c     Fortran list input is used.  Therefore, input for each student may
  23.    2200 c     consist of as many lines as necessary.
  24.    2300 c 
  25.    2400 c     Input is terminated by end-of-file.
  26.    2500 c 
  27.    2600 c     *****     Output     *********************************************
  28.    2700 c 
  29.    2800 c     Output consists of the input, with student scores augmented by the
  30.    2900 c     weighted average of all scores, scaled onto 0% to 100% range
  31.    3000 c     (identified by Raw% column heading), and the T score (identified
  32.    3100 c     by T column heading).  This output is first printed in the order
  33.    3200 c     submitted, and second printed in decreasing order of T scores.
  34.    3300 c 
  35.    3400 c     *****     Parameters     *****************************************
  36.    3500 c 
  37.    3600 c MXSCOR  is the maximum number of scores per student.  If this
  38.    3700 c         parameter is made greater than 14 the Format statements in
  39.    3800 c         procedure (print scores) must be changed.
  40.    3900 c MXSTUD  is the maximum number of students.
  41.    4000 c 
  42.    4100       parameter (MXSCOR=14)
  43.    4200       parameter (MXSTUD=60)
  44.    4300 c 
  45.    4400 c     *****     Variables     ******************************************
  46.    4500 c 
  47.    4600 c DONE    is a signal that end-of-file is present in input.
  48.    4700 c I       is a loop induction variable.
  49.    4800 c ID      is the set of student identification numbers.
  50.    4900 c INUNIT  is the unit number from which to read input.
  51.    5000 c INWT    is the set of relative weights of assignments and
  52.    5100 c         examinations.
  53.    5200 c J       is a loop induction variable.
  54.    5300 c K       is a loop induction variable.
  55.    5400 c LINE    is a line of input, containing an input or output file name.
  56.    5500 c MU      is the mean of composite scores in the RAW vector.
  57.    5600 c MUS     is an array of means of columns of SCORES.
  58.    5700 c NBLANK  is the number of blanks required to center a column heading in
  59.    5800 c         procedure (print scores).
  60.    5900 c NSCORE  is the number of scores per student (assignments and
  61.    6000 c         examinations.
  62.    6100 c NSTDNT  is the number of students.
  63.    6200 c OTUNIT  is the unit number on which to write output.
  64.    6300 c P       is a permutation vector used to sort results into descending
  65.    6400 c         order by T score.
  66.    6500 c PAGHDG  is printed as a page heading for output.
  67.    6600 c RAW     is the set of weighted scores, one per student.  The RAW score
  68.    6700 c         for a student is the weighted average of all assignment and
  69.    6800 c         examination scores.
  70.    6900 c SCORES  is the set of all scores.
  71.    7000 c SIGMA   is the unbiased standard deviation of the RAW scores.
  72.    7100 c SIGMAS  is an array of standard deviations of columns of SCORES.
  73.    7200 c SNAME   is the set of student names.
  74.    7300 c SUMWT   is the sum of weights of assignments and examinations.  See
  75.    7400 c         WEIGHT below for explanation of use of SUMWT.
  76.    7500 c T       is the set of T scores.
  77.    7600 c TOP     is the set of maximum possible scores for assignments and
  78.    7700 c         examinations.
  79.    7800 c TT      is a value of T, used while sorting results by descending
  80.    7900 c         order of T scores.
  81.    8000 c WEIGHT  is the set of weights of assignments.  WEIGHT is used in
  82.    8100 c         calculating the RAW score for each student.  WEIGHT(I) is
  83.    8200 c         INWT(I) / (SUMWT * TOP(I)), where all arithmetic is performed
  84.    8300 c         in floating point.  The inner product of TOP and WEIGHT is 1,
  85.    8400 c         and therefore all elements of RAW are between 0 and 1.
  86.    8500 c 
  87.    8600       character*80 PAGHDG
  88.    8700       character*30 SNAME(MXSTUD)
  89.    8800       integer I,ID(MXSTUD),INWT(MXSCOR),INUNIT,J,K
  90.    8900       character*80 LINE
  91.    9000       integer NBLANK,NSCORE,NSTDNT,OTUNIT
  92.    9100       integer P(MXSTUD),SCORES(MXSTUD,MXSCOR),SUMWT,TOP(MXSCOR)
  93.    9200       logical DONE
  94.    9300       real MU,MUS(MXSCOR),RAW(MXSTUD),SIGMA,SIGMAS(MXSCOR),T(MXSTUD)
  95.    9400       real TT,WEIGHT(MXSCOR)
  96.    9500 c 
  97.    9600       parameter (INUNIT=10, OTUNIT=11)
  98.    9700 c 
  99.    9800 c     *****     Procedures     *****************************************
  100.    9900 c 
  101.   10000 c     Open input file.
  102.   10100 c 
  103.   10200       do forever
  104.   10300       :  print *,'Enter input file name, or CON: for input from the'
  105.   10400       :  print *,'keyboard: '
  106.   10500       :  read (*,'(a80)') line
  107.   10600       :  open (inunit,file=line,err=200)
  108.   10700       <--exit forever
  109.   10800 200   :  print *,'Unable to open input file.  Try again? '
  110.   10900       :  read (*,'(a80)') line
  111.   11000       <--if (line(1:1).eq.'n'.or.line(1:1).eq.'N') stop
  112.   11100       end forever
  113.   11200 c 
  114.   11300 c     Open output file.
  115.   11400 c 
  116.   11500       do forever
  117.   11600       :  print *,'Enter output file name, PRN: for output to the'
  118.   11700       :  print *,'printer, or CON: for output to the console: '
  119.   11800       :  read (*,'(a80)') line
  120.   11900       :  open (otunit,file=line,err=210,carriage control='FORTRAN')
  121.   12000       <--exit forever
  122.   12100 210   :  print *,'Unable to open output file.  Try again? '
  123.   12200       :  read (*,'(a80)') line
  124.   12300       <--if (line(1:1).eq.'n'.or.line(1:1).eq.'N') stop
  125.   12400       end forever
  126.   12500 c 
  127.   12600 c     Read the page heading.
  128.   12700 c 
  129.   12800       read (inunit,'(a80)') paghdg
  130.   12900 c 
  131.   13000 c     Read number of scores, followed by possible score and weight for
  132.   13100 c     each assignment.
  133.   13200 c 
  134.   13300       read (inunit,*) nscore, (top(i),inwt(i), i=1, nscore)
  135.   13400 c 
  136.   13500 c     Calculate sum of input weights.
  137.   13600 c 
  138.   13700       sumwt=0
  139.   13800       do for i = 1, nscore
  140.   13900       :  sumwt=sumwt+inwt(i)
  141.   14000       end for
  142.   14100 c 
  143.   14200 c     Calculate weight = inwt /(top * sum of inwt).  Dividing by top
  144.   14300 c     here saves dividing by top when calculating raw scores.
  145.   14400 c 
  146.   14500       do for i = 1, nscore
  147.   14600       :  weight(i) = float(inwt(i))/float(top(i)*sumwt)
  148.   14700       end for
  149.   14800 c 
  150.   14900 c     Make the averages for each assignment (MUS) zero.  The total of
  151.   15000 c     scores for each assignment will be accumulated in MUS, and then
  152.   15100 c     divided by the number of students to calculate the averages.
  153.   15200 c 
  154.   15300       do for i = 1, nscore
  155.   15400       :  mus(i) = 0.0
  156.   15500       end for
  157.   15600 c 
  158.   15700 c     Read scores for each student.  Compute the raw score and
  159.   15800 c     accumulate the sum of raw scores to compute the mean.
  160.   15900 c 
  161.   16000       mu=0.0
  162.   16100       nstdnt=0
  163.   16200       do forever
  164.   16300       :  nstdnt=nstdnt+1
  165.   16400       :  read (inunit,*,done=end) sname(nstdnt), id(nstdnt)                
  166.   16401      *:  ,                        (scores(nstdnt,i), i=1, nscore)
  167.   16600       <--if (done) exit forever
  168.   16700       :  raw(nstdnt)=0.0
  169.   16800       :  do for i = 1, nscore
  170.   16900       :  :  raw(nstdnt) = raw(nstdnt) + float(scores(nstdnt,i))*weight(i)
  171.   17000       :  :  mus(i) = mus(i) + float(scores(nstdnt,i))
  172.   17100       :  end for
  173.   17200       :  mu = mu + raw(nstdnt)
  174.   17300       end forever
  175.   17400       nstdnt = nstdnt - 1
  176.   17500       if (nstdnt.eq.0) then
  177.   17600       :  print *,' No student scores submitted'
  178.   17700       <--stop
  179.   17800       end if
  180.   17900       if (nstdnt.eq.1) then
  181.   18000       :  print *,' Scores for only one student submitted'
  182.   18100       <--stop
  183.   18200       end if
  184.   18300       mu = mu/float(nstdnt)
  185.   18400 c 
  186.   18500 c     Compute MUS and SIGMAS.
  187.   18600 c 
  188.   18700       do for i = 1, nscore
  189.   18800       :  mus(i) = mus(i)/float(nstdnt)
  190.   18900       :  sigmas(i) = 0.0
  191.   19000       :  do for j = 1, nstdnt
  192.   19100       :  :  sigmas(i) = sigmas(i) + (float(scores(j,i))-mus(i))**2
  193.   19200       :  end for
  194.   19300       :  sigmas(i) = sqrt(sigmas(i)/(nstdnt-1))
  195.   19400       end for
  196.   19500 c 
  197.   19600 c     Compute sigma.
  198.   19700 c 
  199.   19800       sigma=0.0
  200.   19900       do for i = 1, nstdnt
  201.   20000       :  sigma = sigma + (raw(i)-mu)**2
  202.   20100       end for
  203.   20200       sigma = sqrt(sigma/(nstdnt-1))
  204.   20300 c 
  205.   20400 c     Compute T scores.
  206.   20500 c 
  207.   20600       do for i = 1, nstdnt
  208.   20700       :  t(i) = 10.0*(raw(i)-mu)/sigma+50.0
  209.   20800       :  p(i) = i
  210.   20900       end for
  211.   21000 c 
  212.   21100 c     Print results, sort into descending order of T scores, print
  213.   21200 c     results again.
  214.   21300 c 
  215.   21400       nblank = (5*nscore-27)/2
  216.   21500       do (print scores)
  217.   21600       do for k = 2, nstdnt
  218.   21700       :  tt = t(p(k))
  219.   21800       :  do for j = 1, k-1
  220.   21900       :  :  if (tt.gt.t(p(j))) then
  221.   22000       :  :  :  i = p(k)
  222.   22100       :  :  :  p(k) = p(j)
  223.   22200       :  :  :  p(j) = i
  224.   22300       :  :  :  tt = t(i)
  225.   22400       :  :  end if
  226.   22500       :  end for
  227.   22600       end for
  228.   22700       do (print scores)
  229.   22800 c 
  230.   22900       write (otunit,'(''1'')')
  231.   23000       stop
  232.   23100 c 
  233.   23200 c 
  234.   23300       procedure (print scores)
  235.   23400       :  write (otunit,10) paghdg
  236.   23500 10    :  format ('1',a80)
  237.   23600       :  write (otunit,20) (' ',i=1,nblank),' Homework and Examinations '
  238.   23700 20    :  format (t50,70a)
  239.   23800       :  write (otunit,30) (top(i), i = 1, nscore)
  240.   23900 30    :  format (t31,'Possible score',t50,14i5)
  241.   24000       :  write (otunit,40) (inwt(i), i = 1, nscore)
  242.   24100 40    :  format (t31,'Weight',t50,14i5)
  243.   24200       :  write (otunit,50) ('-----', i = 1, nscore)
  244.   24300 50    :  format ('0Student name',t31,'   ID  Raw%   T',t50,14a5)
  245.   24400       :  write (otunit,'()')
  246.   24500       :  do for k = 1, nstdnt
  247.   24600       :  :  i = p(k)
  248.   24700       :  :  write (otunit,60) sname(i),id(i),raw(i),t(i)                   
  249.   24701      *:  :  ,                    (scores(i,j),j=1,nscore)
  250.   24900 60    :  :  format (1x,a30,i5,2pf5.1,0pf5.1,t50,14i5)
  251.   25000       :  end for
  252.   25100       :  write (otunit,70) mu,(mus(i),i=1,nscore)
  253.   25200 70    :  format ('0Mean',t37,2pf5.1,t51,0p14f5.0)
  254.   25300       :  write (otunit,80) sigma,(sigmas(i),i=1,nscore)
  255.   25400 80    :  format (' Standard Deviation',t37,2pf5.1,t51,0p14f5.1)
  256.   25500       end procedure
  257.   25600 c 
  258.   25700       end program
  259.